import { combineReducers } from "redux";
import { IS_LOGIN, SIGN_OUT, USER_INFO_ADD, USER_INFO_REMOVE } from "./actions";
import { setStorage, removeStorage } from "@/utils/global/storage";

// 登录
const isLogin = (state = false, { type }) => {
  switch (type) {
    case IS_LOGIN:
      return true;
    case SIGN_OUT:
      return false;
    default:
      return state;
  }
};

// 用户信息
const userInfo = (state = {}, { type, value }) => {
  switch (type) {
    case USER_INFO_ADD:
      setStorage(USER_INFO_ADD, value);
      return value;
    case USER_INFO_REMOVE:
      removeStorage(USER_INFO_ADD);
      return {};
    default:
      return state;
  }
};

// 所有的 reducer
const reducers = { isLogin, userInfo };
export default combineReducers(reducers); // 导出所有的 reducer